#include "gameboard.h"

GameBoard::GameBoard(QWidget *parent) : QGraphicsView(parent) {
    scene = new QGraphicsScene(this);
    setScene(scene);
    initBoard();
}

void GameBoard::initBoard() {
    // 绘制10x10棋盘
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            QGraphicsRectItem *cell = new QGraphicsRectItem(i*50, j*50, 50, 50);
            cell->setBrush(Qt::lightGray);
            scene->addItem(cell);
        }
    }

    // 初始化玩家棋子
    player = new QGraphicsEllipseItem(5, 5, 40, 40); // 添加5像素边距
    player->setBrush(Qt::red);
    scene->addItem(player);
}

void GameBoard::movePlayer(int position) {
    // 计算棋盘坐标（每行10格）
    int x = (position % 10) * 50 + 5;  // +5保持边距
    int y = (position / 10) * 50 + 5;
    player->setPos(x, y);
}
